<%-- 
    Document   : homeWarehousing
    Created on : Sep 13, 2013, 9:32:22 AM
    Author     : Trang
--%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.Category"%>
<%@page import="java.util.List"%>
<%@page import="model.Role"%>
<%@page import="model.Staff"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>
<!DOCTYPE html>
<%
    Staff staff = (Staff) session.getAttribute("staff");

    if (staff == null) {
        response.sendRedirect(request.getContextPath() + "/Administration");
    } else if (!staff.getRoleList().contains(new Role(1))) {
        response.sendRedirect(request.getContextPath() + "/Administration/home");
    } else {
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Category Management</title>
        <link href="<%= request.getContextPath()%>/css/style_for_page.css" rel="stylesheet" type="text/css"/>
        <link href="<%= request.getContextPath()%>/css/style_for_menu.css" rel="stylesheet" type="text/css"/>
        <link href="<%= request.getContextPath()%>/css/style_addtion.css" rel="stylesheet" type="text/css"/>
        <link href="<%= request.getContextPath()%>/css/style_for_warehousing.css" rel="stylesheet" type="text/css"/>
        <link href="<%= request.getContextPath()%>/css/adMenu.css" rel="stylesheet" type="text/css"/>
        <link href="<%= request.getContextPath()%>/css/tHeaderFooter.css" rel="stylesheet" type="text/css"/>
    </head>
    <script>
        function myFunction()
        {
        var x;
        var r=confirm("You will lose all this category information \nand reference such as receipt, order, etc. \nDo you want to continue?");
        if (r==true)
          {
          $("#deleteProduct").submit();
          }
        else
          {
          x="You pressed Cancel!";
          }
        //document.getElementById("demo").innerHTML=x;
        }
</script>
   <body style="background-color: lightsteelblue;">
        <% int i = 0;%>
        <div class="headerbg">
            <div class="header"> 
                <%@include file="/include/mHeader.jsp" %>
            </div>
            <div class="adContent">
                <div class="adMenu">
                    <%@include file="/include/mMenu.jsp" %>
                </div>
            </div>
        </div>
        <div class="contentbg">
            <div class="content" style="border-bottom:  1px black dashed; ">
                <div style="width: 1024px; color: white; background-color: #610B0B; float:left;margin:auto;">
                    <h3 style="margin-left: 10px;">Category Information</h3>
                </div>
                <div id="errorMessage">
                     <div id="sl12">
                        <img src="<%= request.getContextPath()%>/css/create.png" style="height: 40px; width: 40px;"/>
                    </div>
                    <div id="sl12">
                        <s:form action="searchCategory" namespace="/Administration/Catelogue">     
                            <s:textfield label="Input keyword to search" cssStyle="margin-left:-12px;" name="keyword" size="30" theme="simple" />
                            <s:submit value="Search" cssStyle="width: 100px; margin-left: 12px; background-color: gray;" theme="simple" title="Quick Search"/>
                        </s:form>
                    </div>   
                    <div id="sl12">
                        <s:form namespace="/Administration/Catelogue" action="add-category" >
                            <s:submit value="New Category"  cssStyle="width: 100px; margin-left: 12px;background-color: gray;" theme="simple" title="New Customer"/>
                        </s:form>
                    </div>
                </div>       
            <div class="content2">
                <%
                Integer cate = (Integer) session.getAttribute("category");
//                String[] category = (String []) session.getAttribute("categories");
                if (cate == 1) {   
                %>
                <div class="datagrid2">                  
                    <display:table id="data" export = "true" name="ListCategories" pagesize="8" requestURI="catelogue-management">    
                    <%i++;%>
                    <display:column title="No" media="html" group="1" >
                        <p><%out.print(i);%></p>
                    </display:column>          
                    <display:column property="name" title="Category Name" sortable="true"/>         
                    <display:column property="description" title="Description" sortable="true" /> 
                    <display:column property="parentCategory.name" title="Parent Cateogory" sortable="true" />  
                    <display:column media="html">
                        <a href="<%= request.getContextPath()%>/Administration/Product/edit-product/<s:property value='idProduct'/>" title="<s:property value='description'/>">
                            <img src="<%= request.getContextPath()%>/image/Edit.gif" style="" alt="edit category" width="20" height="auto" title="Eidt Category"/>
                    </display:column> 
                    <display:column media="html">
                        <s:form id="deleteProduct" action="delete-product/%{idProduct}" namespace="/Administration/Product">     
                        </s:form>
                        <img onclick="myFunction()" src="<%= request.getContextPath()%>/image/Delete.gif" style="" alt="delete category" width="20" height="auto" title="Delete Category"/>  
                    </display:column>
                    </display:table>
                </div>
                <% } 
                else
                {%>
                 <div class="datagrid2">                  
                    <display:table id="data" export = "true" name="ListCategories" pagesize="8" requestURI="searchCategory">    
                    <%i++;%>
                    <display:column title="No" media="html" group="1" >
                        <p><%out.print(i);%></p>
                    </display:column>          
                    <display:column property="name" title="Category Name" sortable="true"/>         
                    <display:column property="description" title="Description" sortable="true" /> 
                    <display:column property="parentCategory.name" title="Parent Cateogory" sortable="true" />  
                    <display:column media="html">
                        <a href="<%= request.getContextPath()%>/Administration/Product/edit-product/<s:property value='idProduct'/>" title="<s:property value='description'/>">
                            <img src="<%= request.getContextPath()%>/image/Edit.gif" style="" alt="edit category" width="20" height="auto" title="Eidt Category"/>
                    </display:column> 
                    <display:column media="html">
                        <s:form id="deleteProduct" action="delete-product/%{idProduct}" namespace="/Administration/Product">     
                        </s:form>
                        <img onclick="myFunction()" src="<%= request.getContextPath()%>/image/Delete.gif" style="" alt="delete category" width="20" height="auto" title="Delete Category"/>  
                    </display:column>
                    </display:table>
                </div>
                 <% } %>
            </div>
            </div>
        </div>
        <footer>
            <div id="footer">
                <%@include file="/include/iFooter.jsp" %>
            </div>    
        </footer>

    </body>
</html>
<%
    }
%>